package com.nbsaas.boot.controller.site;

import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.site.api.apis.AdviseApi;
import com.nbsaas.boot.site.api.domain.request.AdviseRequest;
import com.nbsaas.boot.site.api.domain.request.AdviseSearch;
import com.nbsaas.boot.site.api.domain.response.AdviseResponse;
import com.nbsaas.boot.site.api.domain.simple.AdviseSimple;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/advise")
public class AdviseController {


    @Resource
    private AdviseApi adviseApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("advise:search")
    @PostMapping("/search")
    public PageResponse<AdviseSimple> search(@RequestBody AdviseSearch request) {
        return adviseApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("advise:list")
    @PostMapping("/list")
    public ListResponse<AdviseSimple> list(@RequestBody AdviseSearch request) {
        return adviseApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("advise:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<AdviseResponse> create(@RequestBody @Validated(AddOperator.class) AdviseRequest request) {
        return adviseApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("advise:update")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<AdviseResponse> update(@RequestBody @Validated(UpdateOperator.class) AdviseRequest request) {
        return adviseApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("advise:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) AdviseRequest request) {
        return adviseApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("advise:view")
    @PostMapping("/view")
    public ResponseObject<AdviseResponse> view(@RequestBody @Validated(ViewOperator.class) AdviseRequest request) {
        return adviseApi.view(request);
    }
}